package com.bamboo.vodservice.controller;

import com.bamboo.commonutils.ResponseEntity;
import com.bamboo.servicebase.exceptionhandler.BambooException;
import com.bamboo.vodservice.service.VodService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020-07-11
 */
@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {

    @Resource
    private VodService vodService;

    @PostMapping("uploadAlyVideo")
    public ResponseEntity uploadAlyVideo(MultipartFile file) {
        String videoId = vodService.uploadAlyVideo(file);
        return ResponseEntity.ok().data("videoId", videoId);
    }

    @DeleteMapping("/deleteAlyVideo/{videoSourceId}")
    public ResponseEntity deleteAlyVideo(@PathVariable String videoSourceId) {
        if (StringUtils.isEmpty(videoSourceId)) {
            throw new BambooException(20001, "请求参数为空");
        }
        vodService.deleteAlyVideo(videoSourceId);
        return ResponseEntity.ok();
    }

    @GetMapping("/playAuth/{id}")
    public ResponseEntity getPlayAuth(@PathVariable String id) {
        if (StringUtils.isEmpty(id)) {
            throw new BambooException(20001, "请求参数为空");
        }
        String playAuth = vodService.getPlayAuth(id);
        return ResponseEntity.ok().data("playAuth", playAuth);
    }
}
